From: Julius Werner Date: Fri, 2 Jun 2017 22:36:39 +0000 (-0700) Subject: drivers: char: mem: Fix wraparound check to allow mappings up to the end X-Git-Tag: archive/raspbian/4.9.30-2+deb9u2+rpi1~4^2~483 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success/%22http:/www.example.com/cgi/success?a=commitdiff_plain;h=308b705ee628d9d96382088164d163ce1a714980;p=linux-4.9.git drivers: char: mem: Fix wraparound check to allow mappings up to the end commit 32829da54d9368103a2f03269a5120aa9ee4d5da upstream. A recent fix to /dev/mem prevents mappings from wrapping around the end of physical address space. However, the check was written in a way that also prevents a mapping reaching just up to the end of physical address space, which may be a valid use case (especially on 32-bit systems). This patch fixes it by checking the last mapped address (instead of the first address behind that) for overflow. Fixes: b299cde245 ("drivers: char: mem: Check for address space wraparound with mmap()") Reported-by: Nico Huber Signed-off-by: Julius Werner Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/char/mem.c b/drivers/char/mem.c index 6cd8ea271b1b..92bd336503d2 100644 --- a/drivers/char/mem.c +++ b/drivers/char/mem.c @@ -347,7 +347,7 @@ static int mmap_mem(struct file *file, struct vm_area_struct *vma) phys_addr_t offset = (phys_addr_t)vma->vm_pgoff << PAGE_SHIFT; /* It's illegal to wrap around the end of the physical address space. */ - if (offset + (phys_addr_t)size < offset) + if (offset + (phys_addr_t)size - 1 < offset) return -EINVAL; if (!valid_mmap_phys_addr_range(vma->vm_pgoff, size))